#include "Knight.h"

Knight::Knight(enum FigureColor color) : Figure(color)
{
}

QString Knight::getImage() const
{
    if(color == BLACK)
        return "./images/blackknight.png";
    else
        return "./images/whiteknight.png";
}

AllMoves Knight::moves() const
{
    AllMoves m;
    int x, y, position[2];

    Position::position2index(currentPosition, position);

    x = position[1];
    y = position[0];

    //if(y - 2 >= 0) {
        if(x - 1 >= 0 && y - 2 >= 0) {
            QVector <int> coords(2);
            coords[0] = y - 2;
            coords[1] = x - 1;
            m.append(coords);
        }

        if(x + 1 <= 7 && y - 2 >= 0) {
            QVector <int> coords(2);
            coords[0] = y - 2;
            coords[1] = x + 1;
            m.append(coords);
        }

        if(x - 2 >= 0 && y - 1 >= 0) {
            QVector <int> coords(2);
            coords[0] = y - 1;
            coords[1] = x - 2;
            m.append(coords);
        }

        if(x + 2 <= 7 && y - 1 >= 0) {
            QVector <int> coords(2);
            coords[0] = y - 1;
            coords[1] = x + 2;
            m.append(coords);
        }
    //}

    //if(y + 2 <= 7) {
        if(x + 1 <= 7 && y + 2 <= 7) {
            QVector <int> coords(2);
            coords[0] = y + 2;
            coords[1] = x + 1;
            m.append(coords);
        }

        if(x - 1 >= 0 && y + 2 <= 7) {
            QVector <int> coords(2);
            coords[0] = y + 2;
            coords[1] = x - 1;
            m.append(coords);
        }

        if(x + 2 <= 7 && y + 1 <= 7) {
            QVector <int> coords(2);
            coords[0] = y + 1;
            coords[1] = x + 2;
            m.append(coords);
        }

        if(x - 2 >= 0 && y + 1 <= 7) {
            QVector <int> coords(2);
            coords[0] = y + 1;
            coords[1] = x - 2;
            m.append(coords);
        }
    //}

    return m;
}

